<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<style>
  .port-box {
    padding: 16px;
  }
  .port-input {
    margin-bottom: 20px;
    position: relative;
    padding-bottom: 40px;
  }
  .port-input-item {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .port-input-item>input {
    width: 500px;
  }
  .change-url-button {
    position: absolute;
    right: 62%;
    bottom: 0;
  }
</style>
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1 class="m-0 text-dark">参数配置</h1>
      </div><!-- /.col -->
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a th:href="@{../admin}">首页</a></li>
          <li class="breadcrumb-item active">配置中心</li>
          <li class="breadcrumb-item active">参数配置</li>
        </ol>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
  <div class="card card-info">
    <div class="port-box">
      <div class="port-input">
        <div class="port-input-item">
          <span>同步设备信息URL:</span>
          <input class="form-control m-2" id="allDeviceInfoUrl" aria-describedby="basic-addon1" th:value="${allDeviceInfoUrl}">
        </div>
        <div class="port-input-item">
          <span>上传在线时间URL:</span>
          <input class="form-control m-2" id="uploadOnlineTimeUrl" th:value="${uploadOnlineTimeUrl}">
        </div>
        <div class="port-input-item">
          <span>上传采集数据URL:</span>
          <input class="form-control m-2" id="uploadCollectDataUrl" th:value="${uploadCollectDataUrl}">
        </div>
        <button id="changeUrl" type="button" class="btn btn-primary change-url-button">
          <span class="glyphicon glyphicon-edit" aria-hidden="true">提交</span>
        </button>
      </div>

    </div>
  </div>
</section>

<script>
  $(function () {
    $("#changeUrl").click(function() {
      let allDeviceInfoUrl = $("#allDeviceInfoUrl").val();
      let uploadCollectDataUrl = $("#uploadCollectDataUrl").val();
      let uploadOnlineTimeUrl = $("#uploadOnlineTimeUrl").val();
      if (!allDeviceInfoUrl) {
        layer.msg("同步设备信息URL不能为空");
        return;
      }
      if (!allDeviceInfoUrl.startsWith("http://") && !allDeviceInfoUrl.startsWith("https://")) {
        layer.msg("同步设备信息URL必须以http://或https://开头");
        return;
      }
      if (!uploadCollectDataUrl) {
        layer.msg("上传采集数据URL不能为空");
        return;
      }
      if (!uploadCollectDataUrl.startsWith("tcp://")) {
        layer.msg("上传采集数据URL必须以tcp://开头");
        return;
      }
      if (!uploadOnlineTimeUrl) {
        layer.msg("上传在线时间URL不能为空");
        return;
      }
      if (!uploadOnlineTimeUrl.startsWith("http://") && !uploadOnlineTimeUrl.startsWith("https://")) {
        layer.msg("上传在线时间URL必须以http://或https://开头");
        return;
      }
      let json = {
        allDeviceInfoUrl, uploadCollectDataUrl, uploadOnlineTimeUrl
      }
      Core.postAjax("/cfg/param", json, function(res) {
        if (res.code === 1) {
          layer.msg("参数修改成功");
          setTimeout(() => {
            window.location.reload();
          }, 2000)
        } else {
          layer.msg(res.message);
        }
      })
    })
  })
</script>